package com.bjsxt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.EntrustOrder;
import com.bjsxt.model.Result;
import com.bjsxt.service.EntrustOrderService;
import com.bjsxt.util.SpringSecurityUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * description:
 * 委托订单控制层
 *
 * @author ALIENWARE
 * @version v1.0.0
 * @create 06/02/2024
 **/
@RestController
@RequestMapping("/entrustOrders")
@Api(tags = "委托订单控制器")
public class EntrustOrderController {
    /**
     * 委托订单业务层
     */
    @Autowired
    private EntrustOrderService entrustOrderService;

    /**
     * 分页查询委托订单记录
     *
     * @param page   分页对象<EntrustOrder>
     * @param symbol 交易对标识
     * @param type   买卖类型：1-买入；2-卖出,2 卖出
     * @return 统一响应对象
     */
    @GetMapping
    @ApiOperation(value = "分页查询银行卡数据", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "symbol", value = "交易对标识", dataType = "String", paramType = "query", example = "btcgcn"),
            @ApiImplicitParam(name = "type", value = "买卖类型：1-买入；2-卖出,2 卖出", dataType = "Byte", paramType = "query", example = "1")
    })
    public Result<Page<EntrustOrder>> findByPage(@ApiIgnore Page<EntrustOrder> page, String symbol, Byte type) {
        // 获取当前用户 ID
        Long userId = SpringSecurityUtils.getCurrentUserId();
        // 调用业务层进行分页数据的查询
        Page<EntrustOrder> entrustOrderPage = entrustOrderService.pageByUserIdAndSymbolAndType(page, userId, symbol, type);
        // 返回响应数据
        return Result.success(entrustOrderPage);
    }
}
